package nc.impl.pub;

import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import nc.bs.dao.BaseDAO;
import nc.itf.fi.pub.SysInit;
import nc.itf.pub.IParamSetting;
import nc.vo.pub.BusinessException;
import nc.vo.pub.parm.SysParmVO;

public class ParamSettingImpl implements IParamSetting{

	private BaseDAO baseDAO;
	
	private BaseDAO getDAO(){
		if(baseDAO==null){
			baseDAO = new BaseDAO();
		}
		return baseDAO;
	}
	
	@Override
	public String saveSetting(SysParmVO vo) throws BusinessException {
		return getDAO().insertVO(vo);
	}

	@Override
	public Map<String, Object> getParam(String pk_org, String code) throws BusinessException {
		String pk = SysInit.getParaString(pk_org, code);
		SysParmVO vo = (SysParmVO) getDAO().retrieveByPK(SysParmVO.class, pk);
		return new Gson().fromJson(vo.getValue(),  new TypeToken<Map<String, Object>>() {}.getType());
	}

	@Override
	public Map<String, Object> getValueMap(String pk) throws BusinessException {
		SysParmVO vo = (SysParmVO) getDAO().retrieveByPK(SysParmVO.class, pk);
		return new Gson().fromJson(vo.getValue(),  new TypeToken<Map<String, Object>>() {}.getType());
	}

}
